
package com.sailing.lianxi.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

/**
 * 创建线程方式3-2 线程池的方式创建线程
 * @author Administrator
 *
 */
public class FutureThreadTest {
    
    private static long TIME_OUT = 5000; 
    
    public static void t1() throws Exception{
        int taskSize = 5;  
        // 创建一个线程池  
        ExecutorService pool = Executors.newFixedThreadPool(taskSize);
        for(int i=0;i<taskSize;i++){
            //执行线程并返回future
            Future<Integer> result = pool.submit(new MyCallable());
           // System.out.println("线程返回结果："+result.get(TIME_OUT,TimeUnit.MILLISECONDS).toString());
        }
        //关闭线程池
        pool.shutdown();
    }
    
    public static void main(String[] args) {
        try {
            t1();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            
        }
    }
}

